import java.util.HashSet;
import java.util.Iterator;

public class HomeWork17_01{
    public static void main(String[] args){
        HashSet<Fruit> hs = new HashSet<Fruit>();
        Fruit f1 = new Fruit("苹果", 5.5f, "河南");
        Fruit f2 = new Fruit("苹果", 4.0f, "河南");
        Fruit f3 = new Fruit("苹果", 4.6f, "山西");
        Fruit f4 = new Fruit("苹果", 5.5f, "河南");        
        
        hs.add(f1);
        hs.add(f2);
        hs.add(f3);
        hs.add(f4);
        
        Iterator iter = hs.iterator();
        while(iter.hasNext()){
            System.out.println(iter.next());
        }
    }
}

class Fruit{
    String name;
    float price;
    String origin;
    
    public Fruit(String name, float price, String origin){
        this.name = name;
        this.price = price;
        this.origin = origin;
    }
    
    public int hashCode(){
        return this.name.hashCode();
    }
    
    public boolean equals(Object o){
        if(this == o){
            return true;
        }
        
        if(o.getClass() == Fruit.class){
            Fruit f = (Fruit)o;
            return f.name.equals(this.name) && 
                   f.price == this.price && 
                   f.origin.equals(this.origin);
        }
        
        return false;
    }
    
    public String toString(){
        return "[ name: " + name + ", price: " + price + ", origin: " + origin + " ]";
    }
}